<?php
namespace app\admin\model\wxapp;
use think\Model;
/**
 *  分销设置
 * Class DistributionSetting
 * @package app\admin\model\order
 */
class DistributionSetting extends Model
{
    protected $name='distribution_setting';
    public function wxapp(){
        return $this->belongsTo("Wxapp",'wxapp_id','wxapp_id');
    }
    /**
     * 分红开关状态
     */
    public static function getBonusList(){
        return  [ 1 => '已开启', 2 => '关闭中'];
    }

    /**
     * 零钱开关状态
     */
    public static function getMoneyList(){
        return  [ 1 => '已开启', 2 => '关闭中'];
    }
    /**
     * 订单列表
     * @param string $dataType
     * @param array $query
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($query = [])
    {
        // 检索查询条件
        !empty($query) && $this->setWhere($query);
        // 获取数据列表
        return $this->with(['wxapp'])
            ->alias('setting')
            ->field('setting.*')
            ->join('wxapp', 'wxapp.wxapp_id = setting.wxapp_id')
            ->order(['setting.id' => 'desc'])
            ->paginate(10, false, [
                'query' => \request()->request()
            ]);

    }







    /**
     * 设置检索查询条件
     * @param $query
     */
    private function setWhere($query)
    {

        if (isset($query['search']) && !empty($query['search'])) {
            $this->where('wxapp.wxapp_name', 'like', '%' . trim($query['search']) . '%');
        }
        if (isset($query['status']) && !empty($query['status'])) {
            $query['status'] > -1 && $this->where('setting.status', '=', $query['status']);
        }
        // 用户id
        if (isset($query['money_status']) && $query['money_status'] > 0) {
            $this->where('setting.moneypercentstatus', '=', (int)$query['money_status']);
        }

    }

}